package longcaisuyun.longcai.com.yiliubabalongcaisuyun;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

import java.util.List;

import longcaisuyun.longcai.com.mystatic.publicUrl;
import longcaisuyun.longcai.com.suyunbean.ShopBean;


/**
 * Created by Administrator on 2016/4/27.
 */
public class ShangPin_4Adapter extends BaseAdapter {
    Context context;
    List<ShopBean> list;
    ViewHolder vh = null;
    private DisplayImageOptions options = new DisplayImageOptions.Builder()

            .cacheInMemory(false) // 设置下载的图片是否缓存在内存中
            .cacheOnDisk(true) // 设置下载的图片是否缓存在SD卡中
            .displayer(new FadeInBitmapDisplayer(100)).build(); // 构建完成
    private ImageLoader myimageloader = ImageLoader.getInstance();

    public ShangPin_4Adapter(Context context, List<ShopBean> list) {
        this.context = context;
        this.list = list;
    }
    public int getCount() {
        return list.size();
    }
    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            vh = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_shangpin_4, null);
            MyApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);
            vh.imageView40 = (ImageView) convertView.findViewById(R.id.imageView40);
            vh.textView113 = (TextView) convertView.findViewById(R.id.textView113);
        }
        if (list.get(position).getPicurl().length() > 0) {
            myimageloader.displayImage(publicUrl.headurl + list.get(position).getPicurl(),
                    vh.imageView40, options);
        }
        vh.textView113.setText(list.get(position).getTitle());
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(context, ShangPin_3.class);
                intent.putExtra("id", list.get(position).getTypeid());
                intent.putExtra("title", list.get(position).getTitle());
                context.startActivity(intent);
            }
        });
        return convertView;
    }
    class ViewHolder {
        public ImageView imageView40;
        public TextView textView113;
    }
}
